<template>
  <view class="container">
    <view class="header">
      <text class="title">欢迎来到车联网服务平台商家端</text>
			<image src="/static/ltp.png"></image>
		</view>
    
    <view class="form-container">
			
      <view class="input-group">
        <input 
          class="input" 
          type="number" 
          v-model="phone" 
          placeholder="手机号登录"
          maxlength="11"
        />
      </view>
      
      <view class="input-group">
        <input 
          class="input code-input" 
          type="number" 
          v-model="code" 
          placeholder="输入验证码"
          maxlength="6"
        />
        <button 
          class="code-btn" 
          :disabled="isCounting" 
          @click="getVerificationCode"
        >
          {{ countdown > 0 ? `${countdown}s后重新获取` : '获取验证码' }}
        </button>
      </view>
      
      <view class="register">
        <text class="register-text" @click="toRegister">立即注册></text>
      </view>
      
      <button class="login-btn" @click="handleLogin">登录</button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      phone: '',
      code: '',
      isCounting: false,
      countdown: 0
    }
  },
  methods: {
    // 获取验证码
    getVerificationCode() {
      if (!this.phone) {
        uni.showToast({
          title: '请输入手机号',
          icon: 'none'
        })
        return
      }
      
      if (!/^1[3-9]\d{9}$/.test(this.phone)) {
        uni.showToast({
          title: '手机号格式错误',
          icon: 'none'
        })
        return
      }
      
      // 模拟发送验证码
      this.isCounting = true
      this.countdown = 60
      
      let timer = setInterval(() => {
        this.countdown--
        if (this.countdown <= 0) {
          clearInterval(timer)
          this.isCounting = false
        }
      }, 1000)
      
      uni.showToast({
        title: '验证码已发送',
        icon: 'none'
      })
    },
    
    // 登录操作
    handleLogin() {
      if (!this.phone || !this.code) {
        uni.showToast({
          title: '请填写完整信息',
          icon: 'none'
        })
        return
      }
      
      // 这里添加实际登录逻辑
      uni.showLoading({
        title: '登录中...'
      })
      
      // 模拟登录请求
      setTimeout(() => {
        uni.hideLoading()
        uni.showToast({
          title: '登录成功',
          icon: 'success'
        })
        
        // 登录成功后跳转到首页
        uni.reLaunch({
          url: '/pages/index/index'
        })
      }, 1500)
    },
    
    // 跳转到注册页面
    toRegister() {
      uni.navigateTo({
        url: '/pages/register/register'
      })
    }
  }
}
</script>

<style>
/* .container {
  padding: 40rpx;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background-color: #f8f8f8;
} */

.header {
	background-image: url(@/static/lbgt.png);
	height: 23vh;
	text-align: center;
	padding-top: 60rpx;
  /* margin-bottom: 130rpx; */
	position: relative;
}
.header image{
	width: 350rpx;
	height: 250rpx;
	position: absolute;
	right: 30%;
	bottom: -70rpx;
}
.title {
  font-size: 36rpx;
  font-weight: bold;
  color: white;
}

.form-container {
	border-radius: 60rpx;
	background-color: white;
	/* position: relative; */
	/* top: -50rpx; */
	padding: 120rpx 100rpx;
	height: 45vh;
}

.input-group {
  margin-bottom: 40rpx;
  position: relative;

}

.label {
  font-size: 28rpx;
  color: #666;
  margin-bottom: 20rpx;
  display: block;
}

.input {
	border: none;
  height: 90rpx;
  border-radius: 10rpx;
  padding: 0 30rpx;
  font-size: 30rpx;
  border: 2rpx solid #eee;
	border-top: none;    /* 隐藏上边框 */
	  border-right: none;  /* 隐藏右边框 */
	  /* border-bottom: none; */
	  border-left: none;   /* 隐藏左边框 */
	/* border: 1px solid transparent; 隐藏边框*/
}

.code-input {
  width: 400rpx;
}

.code-btn {
  position: absolute;
  right: 0;
 top: 13rpx;
  height: 70rpx;
/* 	top: 0;
	height: 90rpx; */
  width: 200rpx;
	border-radius: 40rpx;
  background-color: #007aff;
  color: white;
  font-size: 28rpx;

  display: flex;
  align-items: center;
  justify-content: center;
}

.code-btn[disabled] {
  color: #999;
}

.register {
  text-align: left;
  margin-bottom: 60rpx;
}

.register-text {
  color: #007aff;
  font-size: 28rpx;
}

.login-btn {
  height: 90rpx;
  background-color: #007aff;
  color: #fff;
  font-size: 32rpx;
  border-radius: 50rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>